import React, { ComponentType, ReactNode } from 'react'
import { useSelector } from 'react-redux'
import { Route, Redirect, RouteComponentProps } from 'react-router-dom'
import { getToken } from '../features/user/slice'

const PrivateRoute: React.FC<{
  path?: string
  exact?: boolean
  component: any
}> = props => {
  const token = useSelector(getToken)
  const { children, ...rest } = props
  return token ? <Route {...rest} /> : <Redirect to="/login" />
}
export default PrivateRoute
